package edu.zut.view;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * web中用于保存数据的对象：
 *  page:this
 *  request（一次请求中间共享）、
 *  session（会话 是每一个用户都有一个,其保存的数据在一个用户的会话周期内，不管发起任何请求都会自动携带）
 *  servletContext（所用用户共享）
 */
public class IndexPageServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Object name = request.getAttribute("name");
        response.getWriter().write("<html>\n" +
                "<head>\n" +
                "    <meta charset=\"UTF-8\">\n" +
                "    <title>首页</title>\n" +
                "</head>\n" +
                "<body>\n" +
                "欢迎" + name + "登录!!!!\n" +

                "<p><a href=" + request.getContextPath() + "/addStu?name=" + name + ">添加学生信息</a></p>\n" +
                "<p><a href=" + request.getContextPath() + "/user/center>个人中心</a></p>" +
                "</body>\n" +
                "</html>\n");
    }
}